Skip to content

Add Manila quota accounting and logical-share inventory - #3

Merged
legit-ninja merged 5 commits into
mainfrom
contrib/manila-2b3
Dec 4, 2026
Merged

legit-ninja merged 5 commits into
mainfrom
contrib/manila-2b3

Conversation

@davidhulick

Copy link
Copy Markdown

Add Manila quota accounting and logical-share inventory

Summary

Add read-only Manila quota accounting and deterministic logical-share inventory queries.

Changes

  • Expose project, user, share-type, and default quota limits.
  • Add raw quota accounting and scoped project/share-type usage totals.
  • Add ShareGetInventory, returning one row per logical share without duplication from multiple share instances.
  • Preserve the existing ShareGetAllWithInstances API and behavior.
  • Include sqlc-generated code, schema fixtures, Go tests, portable SQL tests, and documentation.
  • Enable independent Python SQL-test discovery and MySQL test-driver registration.

Quota consumption is read from Manila's persisted accounting records. Logical-share inventory uses share and instance records. These remain separate sources of information.

Review considerations

  • Raw quota accounting rows can overlap across scopes; consumers should use the scoped totals.
  • Inventory selection preserves the existing multi-instance API while returning a deterministic representative instance.
  • Inventory query performance at production scale remains to be evaluated.
  • Compatibility with older Manila releases has not been established.

ConnectContext pings and closes the pool when the database does not
answer, so a caller that starts during a database outage has no pool
at all. The OpenStack database exporter then reports its services as
down until it is restarted, even after the database is back.

Open does the parsing and pool setup without contacting the server,
and ConnectContext becomes Open plus the ping, so existing callers
behave as before. The pool connects on first use and reconnects
after a lost connection.

Tested with go test -race, go vet, gofmt and the integration suite.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Timon Schnell <timon.schnell@btc-it-services.com>

@adamhackl adamhackl left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Keeping project and share-type accounting separate, and saying clearly that usage is stale until Manila reconciles it, is exactly what consumers need. A few things:

  1. ShareGetInventory query cost
    The correlated subquery picks one instance per share, and its ORDER BY runs two EXISTS subqueries per candidate instance. For a deployment with many shares and replicas, that is a lot of work per call, and it will run on every scrape. Could you run EXPLAIN against a realistically sized dataset, and confirm share_instances.share_id is indexed in the real Manila schema?

  2. NULL usage values are silently treated as zero
    QuotaUsageGetProjectTotals and QuotaUsageGetShareTypeTotals wrap in_use and reserved in COALESCE(…, 0), so malformed rows disappear into the totals. The Neutron PR (#4) returns an InvalidAmounts count so callers can spot bad aggregates. Something similar here, or a note that NULLs count as zero, would keep the libraries consistent.

  3. Usage for deleted share types disappears from type totals
    QuotaUsageGetShareTypeTotals inner-joins on active share types. Any accounting left behind for a deleted type still shows up in the project totals but vanishes from the per-type totals, so the two won’t reconcile. Worth documenting, or using a LEFT JOIN so the orphaned rows stay visible.

  4. Status precedence is tied to Manila 2025.2
    The hard-coded status ranking in ShareGetInventory mirrors Manila’s current Python logic. New upstream statuses fall into the ELSE 6 bucket, so which instance is chosen, and therefore the reported status and availability zone, can change silently after a Manila upgrade. A note on re-checking this against upstream when moving to a new Manila release would help.

  5. The Python SQL tests aren’t wired into CI
    This PR adds tests/manila_quota_sql_test.py and tests/manila_inventory_sql_test.py but doesn’t change ci.yaml. They’ll only run if #1, #2 or #4 lands first with the discovery step.

Open adds no dial timeout, so a pool held through a database outage
does not fail fast. Say so in the Open doc comment and the README,
and move the Open note into its own README paragraph.

Signed-off-by: Mohammed Naser <mnaser@vexxhost.com>
Add Open for a pool without the startup ping
fitbeard and others added 2 commits December 1, 2026 10:52
Add three read-only Designate queries for openstack_database_exporter:

- ZoneGetAll: non-deleted zones with status and type.
- RecordsetCountByZone: recordset count per non-deleted zone, including
  zones with no recordsets, without reading individual records.
- RecordsetGetAllWithStatus: recordsets with the status the Designate API
  reports (worst child record status in the order ERROR, PENDING, ACTIVE,
  DELETED; ACTIVE when a recordset has no records).

Zone and recordset IDs are returned as dashed UUIDs, matching the API.
Splitting the queries lets the exporter skip the per-recordset status
query when that metric is disabled.

Signed-off-by: Tadas Sutkaitis <tadas.sutkaitis@vexxhost.com>
Add ShareGetInventory, which returns one row per nondeleted logical
share, including shares without instances. It follows Manila's
Share.instance rules (status precedence, active-replica preference and
the replication-change exception) and takes status, availability zone
and share type from one representative instance, chosen in a single
pass with window functions. The transitional status ranking copies
constants.TRANSITIONAL_STATUSES and must be re-checked on Manila
upgrades. ShareGetAllWithInstances is unchanged.

Add six read-only quota queries, named after the Manila DB API
functions they follow, that read every project at once and return raw
rows:

- QuotaGetAllByProject, QuotaGetAllByProjectAndUser and
  QuotaGetAllByProjectAndShareType: project, user and share-type
  limit overrides from their separate tables.
- QuotaClassGetDefault: limits of the persisted default quota class.
- QuotaUsageGetAllByProject and QuotaUsageGetAllByProjectAndShareType:
  project and share-type usage rows from quota_usages, with nullable
  in_use and reserved returned as stored rather than summed.

Rows with a NULL or empty project ID are excluded, and results are
ordered by their identifying columns and row ID. The share-type queries
left-join share_types, so limits and usage for deleted share types stay
visible with a NULL name. Quota tables keep Manila's integer soft
delete (deleted = 0 for active rows).

Add the quota tables to the Manila schema fixture, unit tests, MariaDB
integration tests in tests/ with inventory and quota fixtures, smoke
calls in TestManilaQueries, and API.md documentation. Register the
MySQL driver in the integration test helper.

Co-authored-by: David Hulick <dave.hulick@gmail.com>
Signed-off-by: David Hulick <dave.hulick@gmail.com>
Signed-off-by: Jeremy Lee <jeremy.lee1664@gmail.com>
@legit-ninja
legit-ninja merged commit 7b1291b into main Dec 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants